﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.HTML
{
    #region Using Statements

    using System;

    #endregion

    /// <summary>
    /// The anchor element. See the A element definition in HTML 4.01.
    /// </summary>
    public class HTMLAnchorElement : HTMLElement
    {
        #region Constructors

        internal HTMLAnchorElement(Document owner)
            : base(owner, HTMLConstants.HTML_TAG_ANCHOR)
        {
        }

        #endregion

        #region DOM Level 2 HTML Compliance

        /// <summary>
        /// A single character access key to give access to the form control. 
        /// See the accesskey attribute definition in HTML 4.01.
        /// </summary>
        public string accessKey
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_ACCESSKEY);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_ACCESSKEY, value);
            }
        }

        /// <summary>
        /// Removes keyboard focus from this element.
        /// </summary>
        public void blur()
        {
        }

        /// <summary>
        /// The character encoding of the linked resource. See the charset 
        /// attribute definition in HTML 4.01.
        /// </summary>
        public string charset
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CHARSET);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_CHARSET, value);
            }
        }

        /// <summary>
        /// Handle the click behavior for a link.
        /// </summary>
        public override void click()
        {
            //  Perform the standard click behavior
            base.click();

            //  If none of the previous events 
            if (!String.IsNullOrEmpty(href))
            {
                RequestContext linkContext = Owner.Context.ResolveNewContext(href);
                Owner.Context.Window.ExecuteRequest(linkContext);
            }
        }

        /// <summary>
        /// Comma-separated list of lengths, defining an active region 
        /// geometry. See also shape for the shape of the region. See 
        /// the coords attribute definition in HTML 4.01.
        /// </summary>
        public string coords
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_COORDS);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_COORDS, value);
            }
        }

        /// <summary>
        /// The absolute URI [IETF RFC 2396] of the linked resource. See the
        /// href attribute definition in HTML 4.01.
        /// </summary>
        public string href
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_HREF);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_HREF, value);
            }
        }

        /// <summary>
        /// Language code of the linked resource. See the hreflang attribute
        /// definition in HTML 4.01.
        /// </summary>
        public string hreflang
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_HREFLANG);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_HREFLANG, value);
            }
        }

        /// <summary>
        /// Anchor name. See the name attribute definition in HTML 4.01.
        /// </summary>
        public string name
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_NAME);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_NAME, value);
            }
        }

        /// <summary>
        /// Forward link type. See the rel attribute definition in HTML 4.01.
        /// </summary>
        public string rel
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_REL);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_REL, value);
            }
        }

        /// <summary>
        /// Reverse link type. See the rev attribute definition in HTML 4.01.
        /// </summary>
        public string rev
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_REV);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_REV, value);
            }
        }

        /// <summary>
        /// The shape of the active area. The coordinates are given by coords.
        /// See the shape attribute definition in HTML 4.01.
        /// </summary>
        public string shape
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_SHAPE);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_SHAPE, value);
            }
        }

        /// <summary>
        /// Index that represents the element's position in the tabbing order.
        /// See the tabindex attribute definition in HTML 4.01.
        /// </summary>
        public int tabIndex
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_TABINDEX, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_TABINDEX, value);
            }
        }

        /// <summary>
        /// The default target frame. See the target attribute 
        /// definition in HTML 4.01.
        /// </summary>
        public string target
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_TARGET);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_TARGET, value);
            }
        }

        /// <summary>
        /// Advisory content type. See the type attribute definition in 
        /// HTML 4.01.
        /// </summary>
        public string type
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_TYPE);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_TYPE, value);
            }
        }

        #endregion
    }
}
